#define DISCOVERY_REQUEST	1
#define DISCOVERY_RESPONSE	2
#define CHAT_MESSAGE		3

#define DATA_CAPACITY		256

/**
** @struct IFProtMessage
** @brief represents the IF-Chat protocol message struct
** @param type is a integer and represents the type of message
** @param protocol is a integer and represents the transport protocol of message
** @param port_src is a integer and represents the source port of message
** @param port_dst is a integer and represents the destiny port of message
** @param data is a string and represents the data of message
*/

typedef struct {
	uint8_t type;
	int protocol;
	uint16_t port_src;
	uint16_t port_dst;
	char data[DATA_CAPACITY];
} IFProtMessage;

/**
** @fn assign_message
** @brief sets the type, the transport protocol, the ports and the data from a message
** @param message is a pointer IFProtMessage
** @param type is a integer and specifies the type of message
** @param protocol is a integer and specifies the transport protocol of message
** @param port_src is a integer and specifies the source port of message
** @param port_dst is a integer and specifies the destiny port of message
** @param data is a string and specifies the data of message
*/

void assign_message(IFProtMessage* message, uint8_t type, int protocol, uint16_t port_src, uint16_t port_dst, char* data) {
	message->type = type;
	message->protocol = protocol;
	message->port_src = port_src;
	message->port_dst = port_dst;
	strcpy(message->data, data);
}

/**
** @fn create_discovery_request
** @brief creates a discovery request message
** @param message is a pointer of IFProtMessage
*/

void create_discovery_request(IFProtMessage* message) {
	assign_message(message, DISCOVERY_REQUEST, IPPROTO_UDP, port_usr, PORT_STD, username);
}

/**
** @fn create_discovery_response
** @brief creates a discovery response message
** @param message is a pointer of IFProtMessage
*/

void create_discovery_response(IFProtMessage* message) {
	assign_message(message, DISCOVERY_RESPONSE, IPPROTO_UDP, port_usr, PORT_STD, username);
}

/**
** @fn create_chat_message
** @brief creates a chat message
** @param message is a pointer of IFProtMessage
** @param port_dst is a integer and specify the destiny port
** @param data is a data of IFProtMessage
*/

void create_chat_message(IFProtMessage* message, int port_dst, char *data) {
	assign_message(message, CHAT_MESSAGE, IPPROTO_TCP, port_usr, port_dst, data);
}
